class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader
  VALID_EMAIL_REGEX =/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
  VALID_NAME_REGEX = /\A[A-Za-z][A-Za-z0-9._-]{2,19}\z/
  authenticates_with_sorcery!

  has_many :posts,dependent: :destroy
  has_many :musics,dependent: :destroy
  has_many :twitters,dependent: :destroy

  validates :name, presence: true,
            length: { maximum: 100 },
            format: { with: VALID_NAME_REGEX },
            uniqueness: { case_sensitive: false }
  validates :email,presence: true,
             format: { with: VALID_EMAIL_REGEX },
            uniqueness: true
  validates :password, presence: true,
            confirmation: true,
            length: { in: 6..16 },
            on: create
  validates :password_confirmation, presence: true
end
